package com.wrl.mmall.common;

import com.wrl.mmall.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Redisson 初始化方法
 *
 * @author Wang Renlei
 * @Date 2019/10/22 0022
 */
@Slf4j
@Component
public class RedissonManager {

    private Config config = new Config();
    private Redisson redisson = null;

    private static String redisIp = PropertiesUtil.getProperty("redis1.ip");
    private static Integer redisProt = Integer.valueOf(PropertiesUtil.getProperty("redis1.port"));

    public Redisson getRedisson() {
        return redisson;
    }

    @PostConstruct
    private void init() {
        try {
            config.useSingleServer().setAddress(new StringBuilder().append(redisIp).append(":").append(redisProt).toString());
            redisson = (Redisson) Redisson.create(config);
            log.info("初始化redisson结束");
        } catch (Exception e) {
            log.info("redis init error " + e);
        }
    }
}


